/*
 *  GEMath.h
 *  TestGE
 *
 *  Created by Quoc Dung Chu on 14/07/11.
 *  Copyright 2011 Paris 6. All rights reserved.
 *
 */

#ifndef GE_MATH_H
#define GE_MATH_H

#include <math.h>

namespace game_engine {
	namespace vect_math {
		
		const int		ROUNDING_ERROR_INT		= 0;
		const float		ROUNDING_ERROR_FLOAT	= 0.000001f;
		const double	ROUNDING_ERROR_DOUBLE	= 0.00000001;
		
		const float		PI						= 3.14159265359f;
		const float		PI_IN_DEGREE			= 180.0f;
#pragma mark -
#pragma mark COMPARING
		
		inline bool equal ( const int a, const int b) { return a == b; }
		
		inline bool equal ( const float a, const float b ) 
		{
			return a <= b + ROUNDING_ERROR_FLOAT && a >= b - ROUNDING_ERROR_FLOAT;
		}
		
		inline bool equal ( const double a, const double b ) 
		{
			return a <= b + ROUNDING_ERROR_DOUBLE && a >= b - ROUNDING_ERROR_DOUBLE;
		}
		
#pragma mark -
#pragma mark SQUARE ROOT
		
		
		inline float squareroot(float val){ return sqrt(val); }
		
		inline double squareroot(double val){ return sqrt(val); }

		
		inline int squareroot (int val)
		{
			return static_cast<int> (sqrt(static_cast<float> (val)));	
		}
		
		inline float radianToDegree	( float radian )
		{
			return radian * PI_IN_DEGREE / PI;	
			
		}
		
		inline float degreeToRadian ( float degree )
		{
			return degree * PI / PI_IN_DEGREE;
		}
#pragma mark -
#pragma mark MIN,MAX
		template <class T>
		inline T Min( const T& x, const T& y )
		{
			return ( x > y ) ? y : x;
		}
		
		template <class T>
		inline T Max( const T& x, const T& y )
		{
			return ( x > y ) ? x : y;
		}
		
	}
}

#endif
